home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Full / NetObjects Fusion 9 Standard / NOF9_Full_EN.exe / data1.cab / FSI / lib / nof / Util.js < prev   
Encoding:
Text File  |  2005-11-16  |  7.9 KB  |  375 lines

  1. /****i* SOURCE_FILE/INFO
  2.     *
  3.     * NAME
  4.     *  Util.js
  5.     *
  6.     * USAGE
  7.     *  Part of Netobjects JavaScript Library.
  8.     *
  9.     * COPYRIGHT
  10.     *  Copyright ⌐ 2000-2005 Website Pros, Inc.
  11.     *  All Rights Reserved.
  12.     *
  13.     *  This is an unpublished work protected by Website Pros, Inc.
  14.     *  as a trade secret, and is not to be used or disclosed except as
  15.     *  expressly provided in a written license agreement executed by
  16.     *  you and Website Pros, Inc.
  17.     *
  18.     *      <copyright@websitepros.com>
  19.     *
  20.     * NOTES
  21.     *  JavaScript code.
  22.     *
  23.     *****/
  24. if (!IS.isModuleInitialized("IS.NOF.Util"))
  25. {
  26.     //TODO: get out these functions !
  27.     
  28.     /** Populate drop down list of templates.
  29.     **/
  30.     function initTemplateCombo(o, path, s, dir, excludes)
  31.     {
  32.         var iter = new ActiveXObject(NOF.ProgId.FSIDirIterator);
  33.         
  34.         var templatesResources = NOF.UTIL.ResourceBundle.getBundle( 
  35.             "PhotoGallery/PhotoGalleryTemplates", NOF.UTIL.DefaultLocale );
  36.         
  37.         //alert( " templatesResources = " + templatesResources);
  38.         
  39.         var index = 0;
  40.         var i = 0;
  41.         iter.DefineSearch(dir + path, '*');
  42.         
  43.         var mustExclude = (arguments.length==5);
  44.         
  45.         o.options.length = 0;
  46.         
  47.         for (;;)
  48.         {
  49.             var p = iter.GetNext();
  50.             if (!p.length)
  51.                 break;
  52.             
  53.             if(mustExclude){
  54.                 if(typeof(excludes)=="function"){
  55.                     if( excludes(p) )
  56.                         continue;
  57.                 }
  58.             } 
  59.             
  60.             var q = p.split('.');
  61.             if (q.length > 1)
  62.             {
  63.                 if (q[q.length - 1].split('\\').length == 1)
  64.                     continue;
  65.             }
  66.             p = p.split('\\');
  67.             p = p[p.length - 1];
  68.             
  69.             if(mustExclude){
  70.                 
  71.                 if( excludes.constructor == Array ) { 
  72.                     if( excludes.containsItem(p) >= 0 ){        
  73.                         continue;
  74.                     }    
  75.                 }
  76.             }
  77.             
  78.             if (s == p)
  79.                 index = i;
  80.             var theOption = document.createElement("OPTION"); 
  81.             o.options.add(theOption);
  82.             var value = p.replace (/\s/g, "");
  83.             theOption.innerText = ( templatesResources != null && templatesResources.getProperty(value) != null ) ? templatesResources.getProperty(value) : p;
  84.             theOption.value = p;
  85.             i++;
  86.         }
  87.         o.selectedIndex = index;
  88.         iter = null;
  89.     }  
  90.     
  91.     
  92.     function getFileName( filePath ){
  93.         
  94.         var theName = filePath.split('\\');
  95.         return theName[theName.length - 1];
  96.         
  97.     }
  98.     
  99.     
  100.     function orientationToValue(i) {
  101.         switch (i)
  102.         {
  103.         case 0:
  104.             return 0;
  105.         case 1:
  106.             return 90;
  107.         case 2:
  108.             return 270;
  109.         default:
  110.             return 180;
  111.         }
  112.     }
  113.     
  114.     function orientationToIndex(v) {
  115.         switch (v - 0) {
  116.         case 0:
  117.             return 0;
  118.         case 90:
  119.             return 1;
  120.         case 270:
  121.             return 2;
  122.         default:
  123.             return 3;
  124.         }
  125.     }
  126.     
  127.     function spin(o, v, f) {
  128.         o.value = o.value - 0 + v;
  129.         eval(f);//();
  130.     }
  131.     
  132.     function toint(i) {
  133.         var s = '' + i;
  134.         return s.split('.')[0] - 0;
  135.     }
  136.     
  137.     function readFile(fileURL){
  138.         var app = new ActiveXObject(NOF.ProgId.FSIApplication);
  139.         if(app.DoesFileExist(fileURL)){
  140.             var app2 = new ActiveXObject(NOF.ProgId.FSIApplication2);
  141.             return app2.ReadFile(fileURL);
  142.         } else {
  143.             return null;
  144.         }
  145.     }
  146.     
  147.     function getFSIBaseDirectory(){
  148.         var app = new ActiveXObject(NOF.ProgId.FSIApplication);    
  149.         var base = app.SystemDirectory;
  150.         var dir = '';
  151.         if(base.lastIndexOf("\\") == base.length-1){
  152.             dir = base+"FSI";
  153.         } else {
  154.             dir = base+"\\FSI";
  155.         }
  156.         base = null;
  157.         app = null;
  158.         return dir;
  159.     }
  160.     
  161.     function trim(str) {
  162.         i = 0;
  163.         go = true;
  164.         while (go) {
  165.             c = str.charAt(i);    
  166.             if (c == ' ' || c == '\t' || c == '\n') {
  167.                 i++;
  168.             }
  169.             else {
  170.                 go = false;
  171.             }
  172.             if (i>=str.length) {
  173.                 go = false;
  174.             }
  175.         }
  176.         str = str.substr(i);
  177.         i = str.length;
  178.         go = true;
  179.         while (go) {
  180.             c = str.charAt(i);
  181.             if (c == ' ' || c == '\t' || c == '\n') {
  182.                 i--;
  183.             }
  184.             else {
  185.                 go = false;
  186.             }
  187.             if (i==0) {
  188.                 go = false;
  189.             }
  190.         }
  191.         str = str.substr(0,i);
  192.         return str;
  193.     }
  194.     
  195.     
  196.     function showTooltip( source, helpHTML, iWidth, iHeight, ix, iy ) {
  197.         
  198.         var oPopup = window.createPopup();
  199.         var oPopBody = oPopup.document.body;
  200.         oPopBody.style.backgroundColor = "lightyellow";
  201.         oPopBody.style.border = "solid black 1px";
  202.         oPopBody.innerHTML = helpHTML;    
  203.         //oPopup.show( ( (ix) ? ix : (-1*(iWidth/2)) ), ((iy) ? iy : 10), iWidth, iHeight, source);
  204.         var app2 = new ActiveXObject(NOF.ProgId.FSIApplication2);
  205.         oPopup.show( ( (ix) ? ix : (-1*(iWidth/2)) ), ((iy) ? iy : 10), iWidth * app2.LogPixelsX / 96, iHeight * app2.LogPixelsY / 96, source);
  206.         app2 = null;        
  207.     }    
  208.     
  209.     
  210.     /****h* NOF_JavaScript_Library/NOF.Util
  211.     *
  212.     * NAME
  213.     *  NOF.Util
  214.     *
  215.     * DESCRIPTION
  216.     *  
  217.     *    External dependencies: none
  218.     ****/
  219.     
  220.     /**
  221.     * Constructor    
  222.     **/
  223.     function NOF_Util(){
  224.         this.__proto__ = NOF_Util.prototype;
  225.     }
  226.     {
  227.         var method = NOF_Util.prototype;  
  228.         
  229.         method.toFullPath = function (path) {
  230.             var temp = path.split("\\");
  231.             var path = "";
  232.             for (var i = 0; i < temp.length - 1; i++ )
  233.                 path += temp[i] + "\\\\";
  234.             path += temp[temp.length-1];
  235.             
  236.             return path;
  237.         }
  238.         
  239.         method.removeFullPath = function (path) {
  240.             var temp = path.split("\\\\");
  241.             var path = "";
  242.             for (var i = 0; i < temp.length - 1; i++ )
  243.                 path += temp[i] + "\\";
  244.             path += temp[temp.length-1];
  245.             
  246.             return path;
  247.         }
  248.         
  249.         method.formatDate = function (d) {  
  250.             if ( d == 0 || d == null)
  251.                 return "";
  252.             var theDate     = new Date(d * 1000);
  253.             var theMonth     = NOF.Util.shortDate(theDate.getMonth() + 1);
  254.             var theDay         = NOF.Util.shortDate(theDate.getDate());
  255.             var theYear     = NOF.Util.shortDate(theDate.getYear());
  256.             
  257.             return '' + theMonth +  '-' + theDay + '-' + theYear;
  258.         }
  259.         
  260.         method.shortDate = function (d) {
  261.             var s = '' + d;
  262.             switch (s.length) {
  263.             case 0:
  264.                 return '00';
  265.             case 1:
  266.                 return '0' + s;
  267.             case 4:
  268.                 return s.substr(2, 2);
  269.             default:
  270.                 return s;
  271.             }
  272.         }
  273.         
  274.         method.generateGuid = function (uniqueId) {
  275.             var guid = "";
  276.             for (var i = 1; i <= 32; i++) {
  277.                 var n = Math.floor(Math.random() * 16.0).toString(16);
  278.                 guid += n;
  279.                 if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
  280.                     guid += "-";
  281.             }
  282.             guid += "-" + uniqueId;
  283.             return guid;
  284.         }
  285.         
  286.         method.fixDouble = function (validator, value) {
  287.             var newValue = value;
  288.             if (validator != null) {
  289.                 var separator = ".";
  290.                 var tSeparator = ",";
  291.                 var dLength = validator.minLength;
  292.                 
  293.                 if (value == null || validator.isEmptyString(value)) {
  294.                     newValue = "0";
  295.                     var d = "0";
  296.                     if (dLength > 0) {
  297.                         while (d.length < dLength)
  298.                             d = d + "0";
  299.                         newValue += separator + d;
  300.                     }
  301.                     return newValue;
  302.                 }
  303.                 //debugger;
  304.                 var tIndex = value.lastIndexOf (",");
  305.                 var index = value.lastIndexOf (".");
  306.                 if (tIndex > index) {
  307.                     separator = ",";
  308.                     tSeparator = ".";
  309.                     var aux = index;
  310.                     index = tIndex;
  311.                     tIndex = aux;
  312.                 }
  313.                 if (index == -1)
  314.                     index = value.length;
  315.                 
  316.                 
  317.                 var w = value.substring (0,index);
  318.                 var d = value.substring (index+1);
  319.                 
  320.                 // check integer part
  321.                 if (w.indexOf(".") != -1) {
  322.                     var re = new RegExp ("\\.", "g");
  323.                     w = w.replace(re, "");
  324.                 }
  325.                 if (w.indexOf(",") != -1) {
  326.                     var re = new RegExp (",", "g");
  327.                     w = w.replace(re, "");
  328.                 }
  329.                 
  330.                 if (tIndex != -1) {
  331.                     var newWhole = "";
  332.                     var intWhole = w;
  333.                     var toContinue = true;
  334.                     while (toContinue) {
  335.                         var len = intWhole.length;
  336.                         if (len > 3) {
  337.                             newWhole = tSeparator + intWhole.substring (len-3) + newWhole;
  338.                             intWhole = intWhole.substring(0, len-3);
  339.                         }
  340.                         else {
  341.                             newWhole = intWhole + newWhole;
  342.                             toContinue = false;
  343.                         }
  344.                     }
  345.                     w = newWhole;
  346.                 }
  347.                 
  348.                 // check decimal part
  349.                 if (d.length > dLength)
  350.                     d = d.substring (0, dLength);
  351.                 else if (d.length < dLength)
  352.                     while (d.length < dLength)
  353.                         d = d + "0";
  354.                 
  355.                 newValue = w;
  356.                 if (d.length > 0)
  357.                     newValue += separator + d;
  358.             }
  359.             else if (value == null || value.trim() == "")
  360.                 return "0.00";
  361.             
  362.             return newValue;            
  363.         }  
  364.     }
  365.     
  366.     NOF.__proto__.Util = new NOF_Util();    
  367.  
  368. }
  369.  
  370.     
  371.     
  372.     
  373.     
  374.     
  375.